<?php

    require("includes/header.php");

    $bookmark_instance = new bookmark($mysql_connection);

    switch($_GET['mode']) {

        case 'check_b':
            if(isset($_POST['column']) && ($_POST['column'] == 'name' || $_POST['column'] == 'url') && isset($_POST['value']))
                echo $bookmark_instance->check_dupicate_b($_POST['column'], $_POST['value']);
            else
                echo 0;
            break;
        
        case 'add_b':
            if(isset($_POST['category']) && isset($_POST['name']) && isset($_POST['url']) && isset($_POST['comment']))
                echo $bookmark_instance->add_bookmark($_POST['category'], $_POST['name'], $_POST['url'], $_POST['comment']);
            else
                echo 0;
            break;
        
        case 'del_b':
            if(isset($_POST['id']))
                echo $bookmark_instance->delete_bookmark($_POST['id']);
            else
                echo 0;
            break;
        
        case 'move_2_c':
            if(isset($_POST['id']) && isset($_POST['category']))
                echo $bookmark_instance->move_to_category($_POST['id'], $_POST['category']);
            else
                echo 0;
            break;
        
        case 'edit_b':
            if(isset($_POST['id']) && isset($_POST['category']) && isset($_POST['name']) && isset($_POST['url']) && isset($_POST['comment']))
                echo $bookmark_instance->edit_bookmark($_POST['id'], $_POST['category'], $_POST['name'], $_POST['url'], $_POST['comment']);
            else
                echo 0;
            break;

        case 'check_c':
            if(isset($_POST['name']))
                echo $bookmark_instance->check_dupicate_c($_POST['name']);
            else
                echo 0;
            break;
            
        case 'add_c':
            if(isset($_POST['name']) && isset($_POST['description']))
                echo $bookmark_instance->add_category($_POST['name'], $_POST['description']);
            else
                echo 0;
            break;

        case 'edit_c':
            if(isset($_POST['id']) && isset($_POST['name']) && isset($_POST['description']))
                echo $bookmark_instance->edit_category($_POST['id'], $_POST['name'], $_POST['description']);
            else
                echo 0;
            break;

        case 'del_c':
            if(isset($_POST['id']))
                echo $bookmark_instance->delete_category($_POST['id']);
            else
                echo 0;
            break;

        case 'search_c':
            if(isset($_POST['name'])) {
                if($bookmark_instance->search_category($_POST['name'])) {
                    foreach($bookmark_instance->search_category($_POST['name']) as $row)
                        echo "<li title=\"". $entry['description'] ."\"  onclick=\"fill('".$row['name']."', ".$row['id'].");\">".$row['name']."</li>";
                }
            }
            break;

        case 'get_c':

            $row = $bookmark_instance->get_all_category_names();
			if($row) {
	            foreach($row as $entry)
	                echo "<li title=\"". $entry['description'] ."\" onclick=\"fill('".$entry['name']."', ".$entry['id'].");\">".$entry['name']."</li>";
			}
            break;



        default:
            echo "Direkter Aufruf ist nicht gestattet.";
    }


?>